﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Monitor.Models.Json;
using ServiceStack.Text;

namespace Monitor.Controllers.ApiControllers.Administrator
{
    public class ServiseInfoController : MainApiController
    {
        // GET api/seiviceinfo/5
        public ClassifDealerModel Get(Int64 id)
        {
             ClassifDealerModel result=null;
             try
             {
                 var query = DataRepository.ServiceRepository.GetServise(id);
                 if (query != null)
                 {
                     result = new ClassifDealerModel()
                                  {
                                      Id = query.Id,
                                      FullName = query.Classif.FullName,
                                      Contract = query.Contract
                                  };
                 }
             }
             catch (Exception e)
             {
                 ErrorLogger.Fatal(this.ControllerContext,e);
             }
            return result;
        }

        public HttpResponseMessage Post([FromBody]ClassifDealerModel value)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    DataRepository.ServiceRepository.AddOrUpdateService(value.Id,value);
                    return Request.CreateResponse(HttpStatusCode.OK);
                }
                catch (Exception e)
                {
                    ErrorLogger.Error(this.ControllerContext, e);
                    return Request.CreateResponse(HttpStatusCode.Conflict);
                }
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.Forbidden);
            }
        }

        // DELETE api/seiviceinfo/5
        public void Delete(int id)
        {
        }
    }
}
